#include "handelchatmessage.h"
#include <iostream>
#include <string>

namespace QinChat{
    namespace Chat{
        CHandelLoginMessage::CHandelLoginMessage():CChatMessageHandle(){

        }

        CHandelLoginMessage::~CHandelLoginMessage(){

        }

        CChatMessageHandle* CHandelLoginMessage::Clone() {
             return new CHandelLoginMessage(); 
        }

        bool CHandelLoginMessage::HandelMessage(std::shared_ptr<Net::CSession> pSession, rapidjson::Document& doc){
            std::cout<< "login" <<std::endl;

            if(!doc.HasMember("content")){
                pSession->Send("not content", strlen("not content"));
                return false;
            }
             // {"from":"test12345","to":"test123455","type":"login","content":{"user":"test12345", "password":"testaasdf"}}
            rapidjson::Value& content = doc["content"];
            if (!content.HasMember("user")){
                pSession->Send("not user", strlen("not user"));
                return false;
            }
            std::string strUser = content["user"].GetString();

            if (!content.HasMember("password")){
                pSession->Send("not password", strlen("not password"));
                return false;
            }
            std::string strPassword = content["password"].GetString();
            std::cout<<"user is: " << strUser << "  password is: " <<strPassword << std::endl;
        //    pSession->Send("Login Seccess", strlen("Login Seccess"));
            return true;
        }
    }
}